home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Newton Sample Code 1.2 / Recognition / Letter-1 / Letter.π.text < prev    next >
Encoding:
Text File  |  1994-02-28  |  3.5 KB  |  147 lines  |  [TEXT/MPS ]

  1.  
  2.  
  3.  
  4. //this constant may be defined in a future version of NTK
  5. //but we are including currently
  6. constant kLettersDictionary := 33;
  7. // ---- End Project Data ----
  8.  
  9.  
  10. // ---- File Letter.t ----
  11.  
  12. // Before Script for "Single Letter Example"
  13. //Copyright 1993-1994 Apple Computer. All rights reserved.
  14.  
  15. Single Letter Example :=
  16.    {title: "Single Letters",
  17.     viewBounds: {left: 0, top: 18, right: 203, bottom: 309},
  18.     viewEffect: 986145,
  19.     _proto: protoApp,
  20.     debug: "Single Letter Example"
  21.    };
  22.  
  23. usesDictionary := /* child of Single Letter Example */
  24.    {viewBounds: {left: 16, top: 40, right: 184, bottom: 88},
  25.     dictionaries:
  26.       [kLettersDictionary]; // uses the built-in single letter dictionary,
  27.     viewFlags: 25168385,
  28.     textflags: vNoSpaces,
  29.     _proto: protoInputLine,
  30.     debug: "usesDictionary"
  31.    };
  32.  
  33.  
  34.  
  35. _view000 := /* child of Single Letter Example */
  36.    {text: "Uses custom dictionary",
  37.     viewBounds: {left: 18, top: 82, right: 154, bottom: 98},
  38.     viewFont: simpleFont9,
  39.     _proto: protoStaticText
  40.    };
  41.  
  42.  
  43.  
  44. generic := /* child of Single Letter Example */
  45.    {viewBounds: {left: 16, top: 184, right: 184, bottom: 232},
  46.     viewFlags: 8407809,
  47.     textflags: vNoSpaces,
  48.     _proto: protoInputLine,
  49.     debug: "generic"
  50.    };
  51.  
  52.  
  53.  
  54. _view001 := /* child of Single Letter Example */
  55.    {text: "Uses \"vLettersAllowed\" flag",
  56.     viewBounds: {left: 18, top: 226, right: 162, bottom: 242},
  57.     viewFont: simpleFont9,
  58.     _proto: protoStaticText
  59.    };
  60.  
  61.  
  62.  
  63. totallyCustom := /* child of Single Letter Example */
  64.    {viewBounds: {left: 16, top: 112, right: 184, bottom: 160},
  65.     dictionaries: [kLettersDictionary];,
  66.     viewFlags: 25168385,
  67.     textflags: vNoSpaces,
  68.     viewFormat: 337,
  69.     viewWordScript:
  70.       // This code very naively assumes that only A-Z characters are valid letters
  71.       // Do not use code like this if you want to work on non-American Newton systems.
  72.       
  73.       DefConst('kOrdA, ord($A));
  74.       DefConst('kOrdZ, ord($Z));
  75.       DefConst('kDefLetter, "A");
  76.       
  77.       func(unit)
  78.       begin
  79.           local candidate;
  80.           local cOrd;
  81.           local list := GetWordArray(unit);
  82.       print(list);
  83.       
  84.           foreach word in list do begin
  85.               print(isalphanumeric(word[0]));
  86.               cOrd := ord(word[0]);
  87.               if cOrd >= kOrdA and cOrd <= kOrdZ and word[0] <> letter then begin
  88.                   candidate := word;
  89.                   break;
  90.               end;
  91.           end;
  92.           if not candidate then
  93.               candidate := letter & "";
  94.           theShape := MakeText(candidate, 0, 0, width, baseline);
  95.           letter := candidate[0];
  96.           :Dirty();
  97.           TRUE;
  98.           //This should return TRUE if you handled the word
  99.       end ,
  100.     viewSetupDoneScript:
  101.       func()
  102.       begin
  103.           self.baseline := :LocalBox().bottom DIV 2 + 9;
  104.           self.width := :LocalBox().right;
  105.       end,
  106.     baseline: nil,
  107.     theShape: nil,
  108.     viewDrawScript:
  109.       DefConst('kCentered18ptStyle, {font: fancyFont18, justification: 'center});
  110.       
  111.       func()
  112.       begin
  113.           if theShape then
  114.               :DrawShape(theShape, kCentered18ptStyle);
  115.       end,
  116.     width: nil,
  117.     letter: nil,
  118.     viewClickScript:
  119.       func(unit)
  120.       begin
  121.           theShape := nil;
  122.           :Dirty();
  123.           RefreshViews();
  124.           NIL;
  125.       end,
  126.     viewclass: 74,
  127.     debug: "totallyCustom"
  128.    };
  129.  
  130.  
  131.  
  132. _view002 := /* child of Single Letter Example */
  133.    {text: "Totally custom",
  134.     viewBounds: {left: 16, top: 160, right: 160, bottom: 176},
  135.     viewFont: simpleFont9,
  136.     _proto: protoStaticText
  137.    };
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. // ---- Beginning of section for non used Layout files ----
  146.  
  147. // End of output